package com.mc.web;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.mc.model.Article;
import com.mc.model.Path;
import com.mc.model.Teacher;
import com.mc.model.newsandbulletin;
import com.mc.service.ArticleService;
import com.mc.service.NewsandbulletService;
import com.mc.service.TeacherService;
import com.mc.utils.PathUtil;

/**
 * 前台页面对文章显示的公共页面
 */
@Controller
@RequestMapping("/article")
public class ArticleFrontAction {
	@Autowired private ArticleService articleService;					//文章持久层管理
	//@Autowired private APropertyService aPropertyService;				//文章属性数据管理
	//@Autowired private ArticlePropertyService articlePropertyService;	//文章与属性对应中间数据管理
	@Autowired private TeacherService teacherService;
	@Autowired private NewsandbulletService newsandbulletService;
	
	@RequestMapping("/read")
	public String read(ModelMap modelMap, @RequestParam Integer id, @RequestParam(value="view", required=false)String view) {
		Article article = articleService.selectByPrimaryKey(id);
		
		modelMap.addAttribute("article", article);
		
		String sMenu= "1";
		String mMenu = "2";
		if (view != null) {
			if(view.contains("xkjs")){
				sMenu = "rcpy";
				mMenu = "xkjs";
			}else if(view.contains("bkpy")){
				sMenu = "rcpy";
				mMenu = "bkpy";
			}else if(view.contains("kxyj")){
				sMenu = "ScienceYJ";
				mMenu = "other";
			}else if(view.contains("djzc")){
				sMenu = "djzc";
				mMenu = "other";
			}
			else if(view.contains("zsjy")){
				sMenu = "zsjy";
				mMenu = "other";
			}else if(view.contains("xsgz")){
				sMenu = "studentwork";
				mMenu = "other";
			}else if(view.contains("zzjg")){
				sMenu = "AcademyGK";
				mMenu = "other";
			}
			else if(view.contains("shiyanzhongxin")){
				List<Teacher> teacher = teacherService.selectbydid(5);
				//System.out.println(teacher.toString());
				modelMap.addAttribute("teacher",teacher);
				sMenu = "AcademyGK";
				mMenu = "syzx";
			}else if(view.contains("ShuoShiDian")){
				List<newsandbulletin> hotnews=newsandbulletService.selectHotNB("news");
				modelMap.addAttribute("hotnews", hotnews);
				List<newsandbulletin> recentNews = newsandbulletService.selectpNews(0, 5);
				modelMap.addAttribute("recentNews",recentNews);
				sMenu = "rcpy";
				mMenu = "ssd";
			}
		}

		Path path = PathUtil.setPathParams(new String[]{"PackageName:article","ViewName:articleRead","ViewTitle:详细信息","smenu:"+sMenu,"mmenu:"+mMenu,});				
		return PathUtil.returnStr(path, modelMap);
	}
	
}
